/**
 *    Copyright (C) 2008, 2009  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#ifndef _CUBEFS_API_COLLECTIONS_CONTAINER_HPP
#define	_CUBEFS_API_COLLECTIONS_CONTAINER_HPP

#include <cubefs/api/reflection/type_hash.hpp>

#include <cubefs/api/metadata.hpp>

#include <cubefs/api/models/map.hpp>
#include <cubefs/api/models/tree_map.hpp>

#include <cubefs/api/tools/plugin.hpp>

namespace cubefs    {
namespace api       {

enum ContainerTypeCodes {
    STREAM_CONTAINER,
    FILE_CONTAINER,
    SHARED_CONTAINER
};

CUBEFS_DECLARE_TYPENAME(ContainerTypeCodes,    "cubefs::api::ContainerTypeCodes");
CUBEFS_DEFINE_TYPE_HASH(ContainerTypeCodes,    110);

struct Manager;

struct RootMapInterfaceBase {
	virtual Int HashCode() = 0;
};

struct CUBEFS_API Container: public Typed {

	enum {CONTAINER = 0, PAGE_MANAGER = 1};

    virtual Int ContainerType()  = 0;
    virtual void SetContainerType(Int container_type) = 0;

    virtual TreeMap *GetRootMap()                               = 0;
    virtual Manager* GetManager()                               = 0;
    virtual void SetManager(Manager* manager)                   = 0;

    virtual Model* GetCollection(TypedIDValue* rootId)          = 0;
    virtual Model* GetCollectionByName(BigInt name)             = 0;

    virtual Model* CreateCollection(Int type, BigInt name)      = 0;
    virtual void ReleaseCollection(Model* collection)           = 0;
    virtual void RemoveCollection(Model* collection)            = 0;

    virtual bool Check()                                        = 0;

    //virtual void Close()										= 0;
    virtual void SetPlugin(Plugin* plugin)						= 0;
    virtual Plugin* GetPlugin()									= 0;

    virtual ContainerMetadata* 	GetMetadata() 					= 0;

    static Container*  	Create(StringRef name, StringRef version = "0.0.0", Int type = CONTAINER);
    static ListOfTyped*	GetAvailableContainerNames();

    static Type* MyType();

    // for internal use only!
    virtual void* internal_page_mgr() 							= 0;
    virtual RootMapInterfaceBase* GetRootMapInterface() 		= 0;
};

CUBEFS_DECLARE_TYPENAME(Container,    "cubefs::api::models::Container");

void InitContainersMetadata();

}
}


#endif
